/**
 * 版权所有（c）2021. 上海海鼎信息工程股份有限公司，保留所有权利
 */
package com.lovely602.design.creation.abstractfactory.demo;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;

/**
 * 具体产品：水果类
 *
 * @author lizhixing
 */
public class Fruit implements Plant {

  JScrollPane sp;
  JFrame jf = new JFrame("抽象工厂模式测试");

  public Fruit() {
    Container contentPane = jf.getContentPane();
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(1, 1));
    p1.setBorder(BorderFactory.createTitledBorder("植物：水果"));
    sp = new JScrollPane(p1);
    contentPane.add(sp, BorderLayout.CENTER);

    try {
      InputStream is = ClassLoader.getSystemResourceAsStream("image/fruit.jpg");
      Image image = ImageIO.read(is);
      JLabel l1 = new JLabel(new ImageIcon(image));
      p1.add(l1);
      jf.pack();
      jf.setVisible(false);
      //用户点击窗口关闭
      jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } catch (IOException e) {
      e.printStackTrace();
    }

  }

  @Override
  public void show() {
    jf.setVisible(true);
  }
}
